@extends('layouts.public')

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <style>
        .mask{
            position: fixed;
            top:0;
            left:0;
            width:100%;
            height:100vh;
            background: rgba(0,0,0,0.75);
            z-index:1300;
            display: none;
        }
        .content{
            width:250px;
            height:130px;
            background: #fff;
            padding:20px;
            position:absolute;
            top:50%;
            left:50%;
            transform: translate(-50%,-50%);
            z-index:1301;
            border-radius: 5px;
        }
        .item{
            margin: 10px 0;
        }
    </style>
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="{{route('admin.shop.shops')}}">店铺列表</a></li>
                        <li><a href="{{route('admin.shop.shops.add')}}">新增</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <form role="form" class="form-inline" method="get">
                            <div class="form-group">
                                <label class="sr-only">店铺搜索</label>
                                <input type="text" name="title" placeholder="店名/店主/店主联系方式" class="form-control" value="{{request('title')}}">
                            </div>
                            &nbsp;&nbsp;
                            <div class="form-group">
                                <input placeholder="请选择注册时间范围" class="form-control" id="created_at" type="text" name="created_at" value="{{request('created_at')}}" style="width: 200px;"
                                       autocomplete="off">
                            </div>
                            <button type="submit" class="btn btn-primary">搜索</button>
                            <button type="button" class="btn btn-white" onclick="location.href='{{route('admin.shop.shops')}}'">重置</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                            <thead>
                            <tr role="row">
                                <th>店铺ID</th>
                                <th>店招</th>
                                <th>店名</th>
                                <th>店主</th>
                                <th>店主联系方式</th>
                                <th>排名</th>
                                <th>访问量</th>
                                <th>状态</th>
                                <th>服务评星</th>
                                <th class="sorting" orderby="created_at">创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            @foreach($shops as $user)
                                <tr class="gradeA">
                                    <td>{{$user['id']}}</td>
                                    <td><img src="{{$user['avatar']}}" alt=""></td>
                                    <td>{{$user['title']}}</td>
                                    <td>{{$user['username']}}</td>
                                    <td>{{$user['phone']}}</td>
                                    <td>{{$user['rank']}}</td>
                                    <td>{{$user['num']}}</td>
                                    <td>@if($user['status']==2)
                                        <span style="color:red">闭店中</span>
                                        @endif
                                        @if($user['status']==1)
                                            <span style="color:green">营业中</span>
                                        @endif
                                    </td>
                                    <td>{{$user['star']}}</td>
                                    <td>{{$user['created_at']}}</td>
                                   
                                    <td>
                                        <a href="{{route('admin.shop.shops.edit',[$user->id])}}">编辑</a>|
                                        <a href="{{route('admin.shop.shops.comment',[$user->id])}}">评论</a>|
                                        <a href="javascript:void(0)" id="{{$user->id}}" data-status="{{$user->status}}" data-status="{{$user->status}}"  class="setRank">设置排序</a>|
                                        @if($user['status']==2)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.changeShop',[$user->id])}}" msg="显示店铺后，该商家商品均上线，是否显示该店铺？">开启店铺</a>|
                                        @endif

                                        @if($user['status']!=2)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.changeShop',[$user->id])}}" msg="关闭店铺后，该商家商品均下线，是否关闭该店铺？">关闭店铺</a>|
                                        @endif
                                        @if($user['is_recommend']==2)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.recommend',[$user->id])}}" msg="请确认是否推荐该店铺到首页？">设置推荐</a>|
                                        @endif
                                        @if($user['is_recommend']==1)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.recommend',[$user->id])}}" msg="请确认是否取消推荐该店铺到首页？">取消推荐</a>|
                                        @endif
                                        @if($user['show_phone']==1)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.showPhone',[$user->id])}}" msg="请确认是否隐藏该店铺联系方式？">隐藏电话</a>|
                                        @endif
                                        @if($user['show_phone']==0)
                                            <a class="ajaxBtn" href="javascript:void(0);" uri="{{route('admin.shop.shops.showPhone',[$user->id])}}" msg="请确认是否显示该店铺联系方式？">显示电话</a>|
                                        @endif
                                         <a class="ajaxBtn btn btn-danger" href="javascript:void(0);" uri="{{route('admin.shop.shops.delete',[$user->id])}}" msg="删除店铺后，该家商品同步删除，请确认是否删除该店铺？">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                        </table>
                        <div class="row">
                            <div class="col-sm-12">
                                <div>共 {{ $shops->total() }} 条记录</div>
                                {!! $shops->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
                <div class="mask">
                    <div class="content">
                        <div class="item">
                            <input type="text" placeholder="请输入排名，默认0-100降序" class="form-control" id="rank">
                        </div>
                        <div class="btn btn-default" id="cancel">取消</div>
                        <div class="btn btn-primary" id="saveRank">确定</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script type="text/javascript" src="{{cdn('js/plugins/laydate/laydate.js')}}"></script>
    <script type="text/javascript">
        laydate.render({
            elem: '#created_at',
            range: true,
            max: 0
        });
        $(function(){
            $('.setRank').click(function(){
                var id = $(this).attr('id');
                var status = $(this).attr('data-status');
                if(status!=1){
                   return  layer.msg('店铺闭店中，无法排序')
                }
                $('#saveRank').attr('data-id',id);
                $('.mask').show();
                $('#cancel').click(function(){
                    $('.mask').hide();
                })
                $('#saveRank').click(function(){
                    var id = $(this).attr('data-id');
                    var rank = $('#rank').val();
                    if(rank==''&&!/^[0-9]*$/.test(rank)){
                        return layer.msg('请填写数字');
                    }
                    $.ajax({
                        url:'{{route('admin.shop.shops.rank')}}',
                        data:{
                            id:id,
                            rank:rank
                        },
                        type:'POST',
                        success:function(res){
                            if(res.status==1){
                                layer.msg('排序成功');
                                $('.mask').hide();
                                window.location.reload();
                            }
                        },
                        error:function(res){
                            console.log(res);
                        }
                    })
                })

            })
        })

    </script>
@endsection
